<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

//buz api
Route::group([
    'domain' => config('app.website.BUZ_DOMAIN'),
    'namespace' => 'Api',
    'middleware' => ['api']
], function ($router) {
    $router->group([
        'namespace' => 'Buz'
    ], function ($router) {
        $router->post('auth/login', 'AuthController@login')->middleware(['cros']);
        $router->post('auth/register', 'AuthController@register')->middleware(['cros', 'sms.verify:auth']);
        $router->post('auth/doregister', 'AuthController@doRegister');
        $router->post('auth/forgetpwd', 'AuthController@forgetPwd')->middleware(['sms.verify:auth']);
        $router->post('auth/modifypwd', 'AuthController@resetPwd');

        $router->post('tool/sms', 'SMSController@sendSms')->middleware('cros');


        $router->group([
            'middleware' => ['jwt-auth']
        ], function ($router) {

            $router->get('auth/info', 'AuthController@getAuthUser');
            $router->post('auth/loginout', 'AuthController@loginOut');

            //个人基本信息提交
            $router->post('profile/base', 'ProfileController@createBaseInfo');
            //结算信息提交
            $router->post('profile/remit', 'ProfileController@createRemitInfo');

            //必须完善信息才能有权限使用
            $router->group(['middleware' => ['info-complete']], function ($router) {
                $router->get('profile/base', 'ProfileController@baseInfo');
                //登录密码修改
                $router->post('profile/pwd/login', 'ProfileController@loginPwd')->middleware(['sms.verify:remit']);
                $router->post('profile/pwd/trade', 'ProfileController@tradePwd')->middleware(['sms.verify:remit']);

                $router->get('profile/remit', 'ProfileController@remitInfo');
                $router->put('profile/remit', 'RemitController@update')
                    ->middleware(['pwd.verify:trade', 'sms.verify:remit']);

                $router->get('profile/assets', 'ProfileController@getAssetInfo');
                $router->get('profile/payments', 'ProfileController@getPayments');

                $router->post('profile/viewkey', 'ProfileController@viewKey')
                    ->middleware(['pwd.verify:trade', 'sms.verify:remit']);

                $router->get('app/{id}/recharge', 'AppController@rechargeOrders');
                $router->apiResource('app', 'AppController');

                $router->post('tool/sms/remit', 'SMSController@sendSms')->middleware('remitable');
                $router->group(['prefix' => 'order'], function ($router) {
                    $router->get('recharge/{id}', 'RechargeOrderController@show');
                    $router->post('recharge/{id}/callback', 'RechargeOrderController@callback');
                    $router->get('topay', 'ToPayOrderController@index');
                    $router->get('withdraw', 'WithdrawController@index');
                    $router->get('topay/review', 'ToPayOrderController@toPayReview');
                    $router->group(['middleware' => ['remitable', 'pwd.verify:trade']], function ($router) {
                        $router->post('topay/confirm', 'ToPayOrderController@preStore')->middleware();
                        $router->post('topay/single', 'ToPayOrderController@singleStore')->middleware(['sms.verify:remit']);
                        $router->post('topay/batch', 'ToPayOrderController@batchStore')->middleware(['sms.verify:remit']);
                        $router->post('withdraw', 'WithdrawController@store')->middleware(['sms.verify:remit']);
                        $router->post('topay/review', 'ToPayOrderController@toPayReview')->middleware(['sms.verify:remit']);
                    });

                });
            });

            $router->group(['prefix' => 'tool'], function ($router) {
                $router->get('banks', 'ToolController@getBankMap');
                $router->get('cities', 'ToolController@getProvinceCity');
                $router->get('scopes', 'ToolController@getBuzScopes');
                $router->post('imageUpload', 'ToolController@uploadImg');
            });
        });
        $router->get('tool/captcha', 'ToolController@getCaptcha')->middleware(['cros']);

    });

});
